package com.audaque.springboot.foshanupload.web.webdemo.controller;

import com.audaque.springboot.foshanupload.log.anno.WebLogAnno;
import com.audaque.springboot.foshanupload.web.anno.RAnno;
import com.audaque.springboot.foshanupload.web.webdemo.model.req.Covert11Req;
import com.audaque.springboot.foshanupload.web.webdemo.model.req.Covert1Req;
import com.audaque.springboot.foshanupload.web.webdemo.model.req.ScoreReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author zgb
 * @desc ...
 * @date 2023-05-24 19:13:38
 */


@Slf4j
@RestController
@RequestMapping("getterSetter")
public class GetterSetterController {



    @RAnno
    @WebLogAnno
    @GetMapping("/field")
    public Long field() throws Exception {
        Covert1Req covert1Req1 = new Covert1Req();
        covert1Req1.setId(1111L);
        covert1Req1.setSubjectName("aa");
        ScoreReq scoreReq = new ScoreReq();
        scoreReq.setChinese(1111);
        covert1Req1.setScoreReq(scoreReq);
        covert1Req1.setDate(new Date());
        List<Covert11Req> covert11List = new ArrayList<>();
        Covert11Req covert11Req = new Covert11Req();
        covert11Req.setId(1111L);
        covert11Req.setDate(new Date());
        covert11List.add(covert11Req);
        covert1Req1.setCovert11List(covert11List);
        //covert1Req1的id在堆里a，id引用了a
        Long id = covert1Req1.getId();
        //covert1Req1的id在堆里b，id引用了a
        covert1Req1.setId(2222L);
        //所以互不干扰
        return id;
    }

    @RAnno
    @WebLogAnno
    @GetMapping("/field3")
    public ScoreReq field3() throws Exception {
        Covert1Req covert1Req1 = new Covert1Req();
        covert1Req1.setId(11L);
        covert1Req1.setSubjectName("11");
        ScoreReq scoreReq = new ScoreReq();
        scoreReq.setId(11L);
        scoreReq.setChinese(11);
        covert1Req1.setScoreReq(scoreReq);
        covert1Req1.setDate(new Date());
        List<Covert11Req> covert11List = new ArrayList<>();
        Covert11Req covert11Req = new Covert11Req();
        covert11Req.setId(11L);
        covert11Req.setDate(new Date());
        covert11List.add(covert11Req);
        covert1Req1.setCovert11List(covert11List);

        //covert1Req1的scoreReq在堆里a，scoreReq1引用了a
        ScoreReq scoreReq1 = covert1Req1.getScoreReq();
        //covert1Req1的scoreReq在堆里a，a的chinese被改变，scoreReq1引用了a
        covert1Req1.getScoreReq().setChinese(22);
        //所以互相干扰
        return scoreReq1;
    }

}
